﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using PowerCreator.LMS.Logic.Common;

namespace PowerCreator.LMS.Web
{
    public partial class SetManagerCatalog : PowerCreator.LMS.Web.Base.BasePage
    {
        //PowerCreator.LMS.Logic.ActionManager.ManagerGorup groupManager = new PowerCreator.LMS.Logic.ActionManager.ManagerGorup();
        //PowerCreator.LMS.Logic.CourseManager.ManagerCourseType courseTypeManager = new PowerCreator.LMS.Logic.CourseManager.ManagerCourseType();
        //PowerCreator.LMS.Logic.ActionManager.ManagerResource roleManager = new PowerCreator.LMS.Logic.ActionManager.ManagerResource();

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
            //    string groupid = Request.QueryString["GroupID"].ToString();
            //    ViewState["GroupID"] = groupid;
            //    BinderTree();
            //    InitPage();
            //}
        }
        protected override void InitPage()
        {  
            //PowerCreator.LMS.Model.Entity.GorupManager ginfo = new PowerCreator.LMS.Model.Entity.GorupManager();
            //if (!string.IsNullOrEmpty(ViewState["GroupID"].ToString()))
            //{
            //    ginfo = groupManager.load(int.Parse(ViewState["GroupID"].ToString()));
            //}
            //lblGroupName.Text = ginfo.GroupName;
            ////SysMemberType=0为专业
            //DataTable dt = new DataTable();
            //string search = string.Format("RoleGroupID={0} and SysMemberType=1", ViewState["GroupID"]);
            //dt = roleManager.Query(search);
            //Hashtable hsList = new Hashtable();
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    hsList.Add(dt.Rows[i]["MemberID"].ToString(), dt.Rows[i]["MemberID"].ToString());
            //}
            //InitCourseType(tvCatalog.Nodes, hsList);
            base.InitPage();
        }
        private void InitCourseType(TreeNodeCollection nodes, Hashtable list)
        {
            //if (nodes != null)
            //{
            //    foreach (TreeNode var in nodes)
            //    {
            //        if (list.ContainsKey(var.Value))
            //        {
            //            var.Checked = true;
            //        }
            //        InitCourseType(var.ChildNodes, list);
            //    }
            //}
        }

        private void BinderTree()
        {
            //DataTable dt = courseTypeManager.Query("");
            //tvCatalog.Nodes.Clear();
            //InitTree(null, dt, "0");
        }
        private void InitTree(TreeNode pNode, DataTable dt, string parentid)
        {
            //if (dt.Rows.Count > 0)
            //{
            //    DataView dv = new DataView(dt);
            //    dv.RowFilter = "[ParentTypeID]=" + parentid;
            //    foreach (DataRowView drv in dv)
            //    {
            //        TreeNode tempNode = new TreeNode();
            //        if (pNode == null)
            //        {
            //            //填充根节点

            //            tempNode.Text = drv["TypeName"].ToString();
            //            tempNode.Value = drv["TypeID"].ToString();
            //            tempNode.ToolTip = drv["Description"].ToString();
            //            tvCatalog.Nodes.Add(tempNode);
            //            InitTree(tempNode, dt, drv["TypeID"].ToString());
            //        }
            //        else
            //        {
            //            tempNode.Text = drv["TypeName"].ToString();
            //            tempNode.Value = drv["TypeID"].ToString();
            //            tempNode.ToolTip = drv["Description"].ToString();
            //            pNode.ChildNodes.Add(tempNode);
            //            InitTree(tempNode, dt, drv["TypeID"].ToString());
            //        }
            //    }
            //}
        }

        /// <summary>
        /// 获取当前TreeView里面的选中项
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="list"></param>
        private void GetCatalog(TreeNodeCollection nodes, ref string list)
        {
            //if (nodes != null)
            //    foreach (TreeNode var in nodes)
            //    {
            //        if (var.Checked)
            //        {
            //            list += var.Value.ToString() + ",";
            //        }
            //        GetCatalog(var.ChildNodes, ref list);
            //    }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            //string _list = "";
            //GetCatalog(tvCatalog.Nodes, ref _list);
            //if (_list.EndsWith(","))
            //    _list = _list.Remove(_list.Length - 1);

            ////删除己有专业
            //DataTable dt = new DataTable();
            //string search = string.Format("RoleGroupID={0} and SysMemberType=1", ViewState["GroupID"]);
            //dt = roleManager.Query(search);
            //for (int i = 0; i < dt.Rows.Count; i++)
            //{
            //    roleManager.Delete(int.Parse(dt.Rows[i]["PKID"].ToString()));
            //}

            //PowerCreator.LMS.Model.Entity.ManagerResource info = new PowerCreator.LMS.Model.Entity.ManagerResource();
            //info.IsAccredit = 1;
            //info.IsDeleted = 0;
            //info.IsTop = 0;
            //info.SysMemberType = 1;
            //info.RoleGroupID = int.Parse(ViewState["GroupID"].ToString());
            //info.OrderBy = 0;
            //info.DateLastUpdate = DateTime.Now;
            //info.DateCreated = DateTime.Now;

            ////增加所有选中专业
            //string[] list = _list.Split(',');

            //int addcount = 0;
            //for (int i = 0; i < list.Length; i++)
            //{
            //    if (!string.IsNullOrEmpty(list[i]))
            //    {
            //        string groupid = list[i];
            //        info.MemberID = int.Parse(groupid);
            //        if (roleManager.AddNew(info))
            //        {
            //            addcount++;
            //        }
            //    }
            //}
            //if (addcount == list.Length)
            //{
            //    string url = "ActionManage.aspx";
            //    Script.ShowAndRedirect(Page,"保存成功!",url);
            //    //Script.Alert(Page, "msg", "保存成功!");
            //    //return;
            //}
            //else
            //{
            //    Script.Alert(Page, "msg", string.Format("成功保存了{0}条记录", addcount.ToString()));
            //    return;
            //}
        }
        protected void btnBack_Click(object sender, EventArgs e)
        {
            //string url = "ActionManage.aspx";
            //Script.RedirectURL(url);
        }
    }

}